<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item label="款号" class="myform-item">
          <el-input
            v-model="form.type_no"
            placeholder="请输入款号"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="状态" class="myform-item">
          <el-select v-model="form.status">
            <el-option
              v-for="item in cancellationstatus"
              :key="item.status"
              :value="item.status"
              :label="item.title"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="作废日期">
          <el-date-picker
            value-format="yyyy-MM-dd"
            v-model="date"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
      </div>
    </el-form>
    <el-table :data="tableData" style="width: 100%; margin-top: 20px" border>
      <el-table-column label="作废日期" align="center" prop="confirmtime">
      </el-table-column>
      <el-table-column
        label="成品加工单编码"
        align="center"
        prop="processing_code"
      >
      </el-table-column>
      <el-table-column label="SKU编码" align="center" prop="sku_code">
      </el-table-column>
      <el-table-column label="款名" align="center" prop="type_name">
      </el-table-column>
      <el-table-column label="款号" align="center" prop="type_no">
      </el-table-column>
      <el-table-column label="颜色编码" align="center" prop="color_code">
      </el-table-column>
      <el-table-column label="尺码编码" align="center" prop="size_code">
      </el-table-column>
      <el-table-column label="作废流水号" align="center" prop="str_s_number">
        <template slot-scope="{ row }">
          {{ row.str_s_number }} - {{ row.end_s_number }}
        </template>
      </el-table-column>
      <el-table-column label="作废数量" align="center" prop="num">
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="{ row }">
          <div
          :style="{
              color:
                row.status == 1
                  ? '#67C23A'
                  : row.status == 2
                  ? 'red'
                  : '',
            }">
            {{ row.status==0?'待审批':(row.status==1?'已通过':'未通过') }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <div v-if="row.status==0">
            <el-button type="text" @click="onExamine(row.id, 1)"
          >通过</el-button
        >
        <el-button type="text" @click="onExamine(row.id, 2)" style="color:red">拒绝</el-button>
          </div>
          <div v-else>
            --
          </div>
          
        </template>
      </el-table-column>
    </el-table>
    <pagination
      style="clear: both"
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postCodeGetabandoned"
    />
  </div>
</template>

<script>
import { postCodeGetabandoned, postCodeSetapplyabandoned } from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      cancellationstatus:[
        {
          status:0,
          title:"待审批"
        },
        {
          status:1,
          title:"已通过"
        },
        {
          status:2,
           title:"未通过"
          
        }
      ],
      date: "",
      form: {
        status:0,
        type_no: "",
        strtime: "",
        endtime: "",
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 1,
    };
  },
  activated() {
    let form = this.form;
    this.postCodeGetabandoned(form);
  },
  methods: {
    onSearch() {
      this.downloadloading = true;
      let obj = {};
      let form = this.form;
      let date = this.date;
      form.page = 1;
      if (date) {
        form.strtime = date[0];
        form.endtime = date[1];
      } else {
        form.strtime = "";
        form.endtime = "";
      }
      this.postCodeGetabandoned(form);
    },
    // 审批
    onExamine(id, status) {
      this.$confirm(`${status==1?'此操作将永久作废流水号':'此操作将拒绝作废流水号'}, 是否继续?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let obj = {
            id,
            status,
          };
          postCodeSetapplyabandoned(obj).then((res) => {
            let form = this.form;
            this.postCodeGetabandoned(form);
            this.$message({
              type: "success",
              message: `${status == 1 ? "已通过" : "已拒绝"}`,
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 采购列表
    async postCodeGetabandoned(data) {
      this.loading = true;
      this.form = data;
      postCodeGetabandoned(data)
        .then((res) => {
          this.loading = false;
          console.log("采购列表", res);
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.exportdialogVisible {
  > div:nth-child(1) {
    display: flex;
    > div {
      > span {
        font-weight: 600;
      }
    }
  }
  > div:nth-child(2) {
    margin: 20px 0;
    display: flex;
    > span {
      > span {
        font-weight: 600;
      }
    }
  }
  > div:nth-child(3) {
    display: flex;
    align-items: center;
    /deep/ .el-input {
      width: 200px;
      color: #409eff;
    }
  }
}
.cancellationdialogVisible {
  > div:nth-child(1) {
    display: flex;
    > div {
      > span {
        font-weight: 600;
      }
    }
  }
  > div:nth-child(2) {
    margin-top: 20px;
    display: flex;
    align-items: center;
    /deep/ .el-input {
      width: 200px;
    }
    > div:nth-child(3) {
      margin: 0 10px;
      width: 30px;
      height: 1px;
      background: #666;
    }
  }
}
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.export {
  margin-top: 20px;
  display: flex;
  align-items: center;
  float: right;
  > div {
    margin-right: 20px;
    > span {
      color: #409eff;
      font-size: 18px;
      padding: 0 5px;
    }
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
